/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : club.js                                 
*  Description  : 클럽메인 
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-04-16  김효순    Created.  
*  2012-04-17  김효순    Complete.  
*******************************************************************************/

jQuery(function($){
	
	// 검색타입
	function clsSearchType()
	{
		this._HTMLDom = null;
		this.idx = null;
		
		this._init();
	}
	
	clsSearchType.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content div.golf_board article.golf_board_search div.selectlayer:eq(0)");
			
			this._HTMLDom = {
				"$layer": $layer
			}
			this.idx = 0;
			
			this._bind();
		}
		, _bind: function(){
			var thisClass = this;
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("p:eq(0)").click(function(event){
				event.preventDefault();
				
				if($layer.find("ul").css("display")=="block") $layer.find("ul").hide(300);
				else $layer.find("ul").show(300);
			});
			
			$layer.find("li").click(function(event){
				event.preventDefault();
			
				thisClass.setIdx($layer.find("li").index($(this)));
			});
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("p:eq(0) a").html($layer.find("li a").eq(this.idx).html());
		}
		, setIdx: function(idx){
			this.idx = idx;
			//alert("set=" +idx);
			this.display();
			this._HTMLDom["$layer"].find("ul").hide(300);
		}
		, $getSelect: function(){
			return this._HTMLDom["$layer"].find("ul");
		}
		, getValue: function(){
			return this.idx;
		}
	}
	
	// 검색어
	function clsSearchText()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "검색어를 입력해 주십시요."
		}
		this.errMsg = null;
		
		this._init();
	}
	
	clsSearchText.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content div.golf_board article.golf_board_search :text");
			this._HTMLDom = {
				"$layer": $layer
			}
		}
		, getValue: function(){
			return this._HTMLDom["$layer"].val();
		}
		, isValid: function(){
			this.errMsg = null;
			
			if(this.getValue() == ""){
				this.errMsg = this._ERRMSG["_NOVALUE"];
				return false;
			}
			
			return true;
		}
		, getError: function(){
			return this.errMsg;
		}
		, focus: function(){
			this._HTMLDom["$layer"].trigger("focus");
		}
	}
	
	//검색카테고리
	function clsSearchCategory(){
		this._HTMLDom = null;
		this.categoryList = null;
		
		this.idx = null;
		
		this._init();
	}
	
	clsSearchCategory.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content div.golf_board article.golf_board_search div.selectlayer:eq(1)");
			
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("li:first")
			}			
						
			this.idx=0;
			$layer.find("ul").empty();	
			
		}
		, setList: function(thisData){
			this.categoryList = thisData;
			this.display();	
		}
		, display: function(){
			var thisClass= this;
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];

			$layer.find("ul").empty();
			
			for(var i=0;i<this.categoryList.length;++i){
				$layer.find("ul").append($element.clone(true));
			}
			
			$layer.find("li").each(function(n){			

				$(this).find("a").data("카테고리키",thisClass.categoryList[n]["카테고리키"]).html(thisClass.categoryList[n]["카테고리명"]).click(function(event){
					thisClass.setIdx(n);
				});
			});
			
			this._bind();
		}
			
		, _bind: function(){
			var thisClass = this;
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("p:eq(0)").click(function(event){
				event.preventDefault();
				
				if($layer.find("ul").css("display")=="block") {
					$layer.find("ul").hide(300);
				}else {
					$layer.find("ul").show(300);
				}
			});
			
		}		
		, setIdx: function(idx){
			this.idx = idx;
			var $layer = this._HTMLDom["$layer"];			
			
			$layer.find("p:eq(0) a").html($layer.find("ul a").eq(idx).html());
			$layer.find("ul").hide(300);
		}
		, $getSelect: function(){
			return this._HTMLDom["$layer"].find("ul");
		}
		, getValue: function(){
			return this._HTMLDom["$layer"].find("ul a").eq(this.idx).data("카테고리키");
		}
	}
	
	// 동호회 카테고리
	function clsClubCategory()
	{
		this._HTMLDom = null;
		this.categoryData = null;
		
		this._init();
	}
	
	clsClubCategory.prototype = {
		_init: function(){
			var $layer = $("section#main_content div.club_home article.club_home_category ul.tab_menu");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("li:first")
			}
			
			$layer.data("idx", null); // 인덱스로 관리
			
		}
		, setList: function(listData){
			var thisClass = this;
			this.categoryData = listData;
			
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			
			$layer.empty();
			
			for(var i=0;i<this.categoryData.length;++i){
				$layer.append($element.clone(true));
			}
			
			$layer.find("li a").each(function(n){
				$(this).html(thisClass.categoryData[n]["카테고리명"]).live("click",function(event){
					event.preventDefault();
					$(thisClass).trigger("evtTabClick" , [n]);
				});
			});
			
			this.setIdx(0);
			
		}
		, getIdx: function(){
			return this._HTMLDom["$layer"].data("idx");
		}
		, setIdx: function(val){						
			var $layer = this._HTMLDom["$layer"];
			
			if(val == $layer.data("idx")) return false;
			
			$layer.data("idx", val);
			this.display();
			
			return true;
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"]
			var $tabs = $layer.find("li");
			var idx = $layer.data("idx");
			
			// 모든 탭 off 설정
			$tabs.removeClass("tab_on");
			
			if(idx == null) return;
						
			// 선택탭 on 설정
			$tabs.eq(idx).addClass("tab_on");
		}
		
	}
	
	//신규동호회
	function clsClubListNew(){
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsClubListNew.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content div.club_home article.list01 table:eq(0) tbody");
			
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("tr:first")
				, "$empty": $("body").find("article.board_list_none:eq(1)").html("등록된 글이 없습니다.")
			}
			
			$layer.empty();
		}	
		, setList: function(thisData){
			this.listData = thisData;
			this.display();			
		}
		, display: function(){
			var thisClass = this;
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			
			$layer.empty();
			this.isNoData();
			
			for(var i=0;i<this.listData.length;++i){
				$layer.append($element.clone(true));	
			}
								
			$layer.find("tr").each(function(n){
				$(this).find("td.club_name").css("cursor", "pointer").html(thisClass.listData[n]["동호회명"]).click(function(event){
					event.preventDefault();
					document.location.href="../self_club/home.html?club_seq=" + thisClass.listData[n]["키"];
					//-->
				});
				$(this).find("td:eq(1)").html(thisClass.getFormatDateYmd(thisClass.listData[n]["개설일"],". "));
				$(this).find("td.name").html(thisClass.listData[n]["매니저"]).hover(function(event){
					_gf.showProfileLayer($(this), thisClass.listData[n]["프로필"], "left", 30, 33);
				}, function(event){
					_gf.closeProfileLayer();
				});
				$(this).find("td strong").html(thisClass.getFormatNumber(thisClass.listData[n]["회원수"]));
			});
						
		}
		, spinStart: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.hide();
			if($layer.parent().parent().prev("#tmpSpin").length == 0){
				$layer.parent().parent().before("<div id='tmpSpin' style='position:absolute; left:350px; top:360px;'></div>");
			}
			$layer.parent().parent().prev("#tmpSpin").spin();
		}
		, spinEnd: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.parent().parent().prev("#tmpSpin").spin(false);
			$layer.show();
		}
		, getFormatDateYmd: function (n,v){			
			n = String(n);
			
			return n.substr(0,4) +v+ n.substr(4,2) +v+ n.substr(6,2);
		}
		, getFormatNumber: function(n){
			n = String(n);			
			i = n.length;
			r = "";
			while(true){				
				if(i<=3) {
					r = n.substr(0,i) + r;					
					break;
				}
				r = ","+ n.substr(i-3,3) + r;				
				i-=3;
			}
			return r;
		}
		, isNoData: function(){
			if(!this.listData.length) {
				this._HTMLDom["$empty"].show();
				$("div#idNewClubListPage").hide();
			}else {
				this._HTMLDom["$empty"].hide();
				$("div#dNewClubListPage").show();
			}
		}
		, addProfile: function(idx, oneData){
			this.listData[idx]["프로필"] = oneData;
		}
	}
	
	//동호회라운드
	function clsClubListSchedule(){
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsClubListSchedule.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content div.club_home article.list01 table:eq(1) tbody");
			
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("tr:first")
				, "$empty": $("body").find("article.board_list_none:eq(2)").html("등록된 글이 없습니다.")
			}
			
			$layer.empty();
		}	
		, setList: function(thisData){
			this.listData = thisData;
			this.display();			
		}
		, display: function(){
			var thisClass = this;
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			
			$layer.empty();
			this.isNoData();
			
			for(var i=0;i<this.listData.length;++i){
				$layer.append($element.clone(true));	
			}
											
			$layer.find("tr").each(function(n){
				$(this).find("td:eq(0)").css("cursor", "pointer").html(thisClass.listData[n]["동호회명"]).click(function(event){
					event.preventDefault();
					var _url = "../self_club/club_admin_rd.html";
					var _param = "?club_seq=" + thisClass.listData[n]["키"];
					if(thisClass.listData[n]["회원유무"]=="0") {
						_url = "../self_club/club_admin_rd_view.html";						
						 _param += "&round_seq=" + thisClass.listData[n]["라운드키"];
					}
					document.location.href=_url + _param;
					//-->
					
				});
				$(this).find("td.day").html(thisClass.getFormatDateYmd(thisClass.listData[n]["라운드정보"]["일자"],". ") + "(" + thisClass.listData[n]["라운드정보"]["요일"] + ")");
				$(this).find("td:eq(2) strong").html(thisClass.listData[n]["라운드정보"]["코스명"]);
				$(this).find("td:eq(2)").contents().filter(function(){
					return (this.nodeType==3&&this.data.trim());
				}).after("").remove();
				
				//진행-P,확정-C,마감-D
				if(thisClass.listData[n]["라운드정보"]["진행상태"]=="P"){
					$(this).find("td:eq(3)").attr("src", "../images/btn/btn_ing.png");
				}else if(thisClass.listData[n]["라운드정보"]["진행상태"]=="C"){
					$(this).find("td:eq(3)").attr("src", "../images/btn/btn_ok.png");
				}else if(thisClass.listData[n]["라운드정보"]["진행상태"]=="D"){
					$(this).find("td:eq(3)").attr("src", "../images/btn/btn_end.png");
				}
				
				$(this).find("td:eq(4)").html(thisClass.listData[n]["제목"]);
			});
			
		}
		, spinStart: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.hide();
			if($layer.parent().parent().prev("#tmpSpin").length == 0){
				$layer.parent().parent().before("<div id='tmpSpin' style='position:absolute; left:350px; top:450px;'></div>");
			}
			$layer.parent().parent().prev("#tmpSpin").spin();
		}
		, spinEnd: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.parent().parent().prev("#tmpSpin").spin(false);
			$layer.show();
		}
		, getFormatDateYmd: function (n,v){			
			n = String(n);
			
			return n.substr(0,4) +v+ n.substr(4,2) +v+ n.substr(6,2);
		}
		, getFormatNumber: function(n){
			n = String(n);			
			i = n.length;
			r = "";
			while(true){				
				if(i<=3) {
					r = n.substr(0,i) + r;					
					break;
				}
				r = ","+ n.substr(i-3,3) + r;				
				i-=3;
			}
			return r;
		}
		, isNoData: function(){
			if(!this.listData.length) {
				this._HTMLDom["$empty"].show();
				$("div#idScheduleClubListPage").hide();
			}else {
				this._HTMLDom["$empty"].hide();
				$("div#idScheduleClubListPage").show();
			}
		}
	}
	
	function clsClubListPopular(){
		this._HTMLDom = null;
		this.listData = null;
		this.rolling = true;
		this._init();
	}
	
	clsClubListPopular.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content div.club_home article.club_home_banner");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("dl:first")
				, "$empty": $("body").find("article.board_list_none:eq(0)").html("등록된글이 없습니다.")
			}			
			$layer.empty();
			
		}	
		, setList: function(thisData){
			this.listData = thisData;
			this.display();
		}
		, display: function(){
			var thisClass = this;
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
						
			$layer.empty();
			this.isNoData();
			
			for(var i=0;i<this.listData.length;++i){
				$layer.	append($element.clone(true));
			}
			
				
			$layer.find("dl").each(function(n){				
				$(this).find("dt img").attr("src",_gf.filePath2Url(thisClass.listData[n]["이미지"]));
				$(this).find("li.club_name a").html(thisClass.listData[n]["동호회명"]).click(function(e){
					e = e || event;
					e.preventDefault();
					document.location.href = "../self_club/home.html?club_seq=" + thisClass.listData[n]["키"];
					//-->
				});				
				$(this).find("li.name").html(thisClass.listData[n]["닉네임"]).hover(function(event){
					_gf.showProfileLayer($(this), thisClass.listData[n]["프로필"], "left", 0, 15);
				}, function(event){
					_gf.closeProfileLayer();
				});
				$(this).find("li.members").html(thisClass.getFormatNumber(thisClass.listData[n]["회원수"]));
				$(this).find("li.comment").html(thisClass.getFormatNumber(thisClass.listData[n]["댓글수"]));
				$(this).find("div").html(thisClass.listData[n]["동호회설명"]);
				$(this).find("p a.prev").click(function(event){
					thisClass.goNext(n-1);
				});
				$(this).find("p a.next").click(function(event){
					thisClass.goNext(n+1);
				});
				
				$(this).find("ol li a").removeClass("on").eq(n).addClass("on");
				
				$(this).find("ol li a").hover(function(event){
					thisClass.rolling = false;
					var idx =  $layer.find("ol").eq(n).find("li a").index($(this));					
					$layer.find("dl").hide().eq(idx).show();
				}, function(event){
					thisClass.rolling = true;			
				});
				
			}).not("dl:first").hide();
			/*
			$layer.hover(function(event){
				thisClass.rolling = false;
			}, function(event){
				thisClass.rolling = true;				
			});
			*/
			this.showTime(0);
			
		}
		, spinStart: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.hide();
			if($layer.prev("#tmpSpin").length == 0){
				$layer.before("<div id='tmpSpin' style='position:absolute; left:350px; top:150px;'></div>");
			}
			$layer.prev("#tmpSpin").spin();
		}
		, spinEnd: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.prev("#tmpSpin").spin(false);
			$layer.show();
		}
		, getFormatNumber: function(n){
			n = String(n);			
			i = n.length;
			r = "";
			while(true){				
				if(i<=3) {
					r = n.substr(0,i) + r;					
					break;
				}
				r = ","+ n.substr(i-3,3) + r;				
				i-=3;
			}
			return r;
		}
		, isNoData: function(){
			if(!this.listData.length) {
				this._HTMLDom["$empty"].show();
				this._HTMLDom["$layer"].hide();
			}else {
				this._HTMLDom["$empty"].hide();
				this._HTMLDom["$layer"].show();
			}
		}
		, addProfile: function(idx, oneData){
			this.listData[idx]["프로필"] = oneData;
		}
		, goNext: function(v){
			var $layer = this._HTMLDom["$layer"];
		
			var $min = 0;
			var $max = this.listData.length-1;
			
			if($min > v) {
				v= 0; 
				//alert("맨앞");
			}
			if($max < v) {
				v = $max; 
				//alert("맨끝");
			}
			
			$layer.find("dl").hide().eq(v).show();			
		}
		, showTime: function(){
			var $layer = this._HTMLDom["$layer"];
			var thisClass = this;
			
			setTimeout(function(){
				
				var n = $layer.find("dl").index($layer.find("dl:visible"));
				var $max = $layer.find("dl").length-1;
				
				if(n==$max) {
					n = -1;
				}
				
				if(thisClass.rolling) {
					thisClass.goNext(n+1);					
				}
								
				thisClass.showTime();				
				
			},2000);
			
		}
	}
	
	// 동호회 카테고리 리스트
	function clsClubListCategory()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsClubListCategory.prototype = {
		_init: function(){
			var $layer = $("section#main_content div.club_home article.club_home_category tbody");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("tr:first").clone(true)
			}
			
			$layer.empty();
		}
		, setList: function(thisData){
			this.listData = thisData;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.empty();
			for(var i=0;i<this.listData.length;i++){
				$layer.append($element.clone(true));
			}
			
			// 데이터링
			$layer.find("tr").each(function(n){
				$(this).find("div.td_tit a").click(function(event){
					event.preventDefault();					
					document.location.href = "../self_club/home.html?club_seq=" + thisClass.listData[n]["키"];
					//-->
				}).html(thisClass.listData[n]["동호회명"]);
				$(this).find("td div:eq(1)").html(thisClass.listData[n]["인사말"]);
				$(this).find("p.rate").html(thisClass.getFormatNumber(thisClass.listData[n]["회원수"]));
				
				if(thisClass.listData[n]["새글수"]){
					$(this).find("p.new").html(thisClass.getFormatNumber(thisClass.listData[n]["새글수"]));
					$(this).find("td.align_c").html(thisClass.listData[n]["경과시간"]);
				}else{
					$(this).find("p.new").hide();
					$(this).find("td.align_c").html("");
				}
			});
		}
		, spinStart: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.hide();
			if($layer.parent().parent().prev("#tmpSpin").length == 0){
				$layer.parent().parent().before("<div id='tmpSpin' style='position:absolute; left:350px; top:950px;'></div>");
			}
			$layer.parent().parent().prev("#tmpSpin").spin();
		}
		, spinEnd: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.parent().parent().prev("#tmpSpin").spin(false);
			$layer.show();
		}
		, getFormatNumber: function(n){
			n = String(n);			
			i = n.length;
			r = "";
			while(true){				
				if(i<=3) {
					r = n.substr(0,i) + r;					
					break;
				}
				r = ","+ n.substr(i-3,3) + r;				
				i-=3;
			}
			return r;
		}
	}
	
	function clsComm()
	{
		this.category = null;
		
		this.categoryClubList = null;
		this.categoryClubRequest = null;
		this.categoryClubPageData = null;
		
		this.newClubList = null;
		this.newClubRequest = null;
		this.newClubPageData = null;
		
		this.popularClubList = null;
		this.popularClubRequest = null;
		
		this.scheduleClubList = null;
		this.scheduleClubRequest = null;
		
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){
			this.category = {					
					"카테고리키": null
					, "카테고리명": null
			}	
			
//------------------------ 카테고리별동호회------------------------//					
			this.categoryClubPageData = {
				"전체수":null
			}
			
			this.categoryClubRequest = {
				"카테고리키": null
				, "페이지": null
				, "검색어":null
				, "검색종류":null
			}		
//------------------------ 신규별동호회------------------------//		
			this.newClubPageData = {
				"전체수":null
			}
			
			this.newClubRequest = {
				 "페이지": null
			}
//------------------------ 라운드별동호회------------------------//		
			this.scheduleClubPageData = {
				"전체수":null
			}
			
			this.scheduleClubRequest = {
				 "페이지": null				
			}
//------------------------ 인기별동호회------------------------//		
			this.popularClubRequest = {
				 "페이지": null				
			}
		}		
//------------------------ 카테고리구분------------------------//		
		, getCategory: function(){
			var thisClass = this;
			
			// ajax 시작			
			//parameter setting and run
			_gf.ajax({
				"sid":"CL001",
				"servicename":"getCategoryList"
			}, {
				
			}, function(ret){
				
				// callback and mapping
				thisClass.category = [];
				
				if(ret["msp"]["contents"]["items"]){
					if(!ret["msp"]["contents"]["items"].length){
						ret["msp"]["contents"]["items"] = new Array(ret["msp"]["contents"]["items"]);
					}
					for(var i=0;i<ret["msp"]["contents"]["items"].length;i++){
						thisClass.category.push({
							"카테고리키": ret["msp"]["contents"]["items"][i]["categoryId"]
							, "카테고리명": ret["msp"]["contents"]["items"][i]["categoryName"]
						});
					}
				}
				
				$(thisClass).trigger("evtFinishCategory");
			});
			// ajax 끝
		}
		, getCategoryData: function(){
			return this.category;
		}
//------------------------ 카테고리별동호회------------------------//		
		, getCategoryClubList: function(){
			var thisClass = this;
			var szPage = this.categoryClubRequest["페이지"];	
			var szCategory = this.categoryClubRequest["카테고리키"];	
			var szTitle = "";
			var szContent =  "";
			var szNickName = "";
			
			switch(this.categoryClubRequest["검색종류"]){
				case 0: szTitle = szContent = szNickName = this.categoryClubRequest["검색어"]; break; //전체
				case 1:  szTitle = this.categoryClubRequest["검색어"]; break;	//제목
				case 2:  szContent =  this.categoryClubRequest["검색어"]; break;//제목+내용
				case 3:  szNickName	= ""; break;//작성자
				default : break;
			}
			
			// ajax 시작			
			//parameter setting and run
			_gf.ajax({
				"sid":"CL001",
				"servicename":"getList",
				"listcount":10,
				"currpageno":szPage
			}, {
				"scope": 1
				, "categoryId": szCategory
				, "title": szTitle
				, "content" : szContent
				, "nickname": szNickName
			}, function(ret){
				
				thisClass.categoryClubPageData = {
					"전체수": ret["msp"]["contents"]["@totalcount"]
				}
				
				// callback and mapping
				thisClass.categoryClubList = [];
				
				if(ret["msp"]["contents"]["items"]){
					if(!ret["msp"]["contents"]["items"].length){
						ret["msp"]["contents"]["items"]	= new Array(ret["msp"]["contents"]["items"]);
					}
					for(var i=0;i<ret["msp"]["contents"]["items"].length;i++){
						var timelag = "";
						if(ret["msp"]["contents"]["items"][i]["clubBoard"]) timelag = ret["msp"]["contents"]["items"][i]["clubBoard"]["timelag"] ;
						
						thisClass.categoryClubList.push({
							"키": ret["msp"]["contents"]["items"][i]["clubSeq"]
							, "동호회명": ret["msp"]["contents"]["items"][i]["clubName"]
							, "인사말": ret["msp"]["contents"]["items"][i]["clubDesc"]
							, "새글수": ret["msp"]["contents"]["items"][i]["newBoardCnt"]
							, "회원수": ret["msp"]["contents"]["items"][i]["memberCnt"]							 
							, "경과시간": timelag
						});
					}
					
				}
				
				$(thisClass).trigger("evtFinishCategoryClubList");
			});
			// ajax 끝
			
		}
		, getCategoryClubData: function(){
			return this.categoryClubList;
		}
		, getCategoryClubPageData: function(){
			return this.categoryClubPageData;
		}
		, setCategoryClubRequest: function(key, val){
			this.categoryClubRequest[key] = val;
		}
		, getCategoryClubRequest: function(key){
			return this.categoryClubRequest[key];
		}
//------------------------ 신규동호회-----------------------------//		
		, getNewClubList: function(){
			var thisClass = this;
			var szPage = this.newClubRequest["페이지"];
			
			// ajax 시작			
			//parameter setting and run
			_gf.ajax({
				"sid":"CL001",
				"servicename":"getList",
				"listcount":5,
				"currpageno":szPage
			}, {
				"scope": 3
				, "categoryId": ""
			}, function(ret){
				
				thisClass.newClubPageData = {
					"전체수": ret["msp"]["contents"]["@totalcount"]
				}
				
				// callback and mapping
				thisClass.newClubList = [];
								
				if(ret["msp"]["contents"]["items"]){
					if(!ret["msp"]["contents"]["items"].length){				
						ret["msp"]["contents"]["items"] = new Array(ret["msp"]["contents"]["items"]);
					}		
					for(var i=0;i<ret["msp"]["contents"]["items"].length;i++){
						thisClass.newClubList.push({
							"키": ret["msp"]["contents"]["items"][i]["clubSeq"]
							, "동호회명": ret["msp"]["contents"]["items"][i]["clubName"]
							, "개설일": ret["msp"]["contents"]["items"][i]["regDate"]
							, "매니저": ret["msp"]["contents"]["items"][i]["userMaster"]["nickname"]
							, "아이디": ret["msp"]["contents"]["items"][i]["userMaster"]["userId"]
							, "회원수":  ret["msp"]["contents"]["items"][i]["memberCnt"]
							, "프로필": []
						});
					}
				}				
				$(thisClass).trigger("evtFinishNewClubList");
			});
			// ajax 끝
			
		}
		, getNewClubData: function(){
			return this.newClubList;
		}
		, getNewClubPageData: function(){
			return this.newClubPageData;
		}
		, setNewClubRequest: function(key, val){
			this.newClubRequest[key] = val;
		}
		, getNewClubRequest: function(key){
			return this.newClubRequest[key];
		}		
//------------------------ 라운드동호회-----------------------------//		
		, getScheduleClubList: function(){
			var thisClass = this;
			var szPage = this.scheduleClubRequest["페이지"];
			
			// ajax 시작			
			//parameter setting and run
			_gf.ajax({
				"sid":"CL001",
				"servicename":"getClubRoundList",
				"listcount":5,
				"currpageno":szPage
			}, {
				"clubSeq":null
			}, function(ret){
				
				thisClass.scheduleClubPageData = {
					"전체수": ret["msp"]["contents"]["@totalcount"]
				}
				
				// callback and mapping
				thisClass.scheduleClubList = [];
						
				if(ret["msp"]["contents"]["items"]){
					if(!ret["msp"]["contents"]["items"].length){
						ret["msp"]["contents"]["items"] = new Array(ret["msp"]["contents"]["items"]);
					}
					for(var i=0;i<ret["msp"]["contents"]["items"].length;i++){
						
						thisClass.scheduleClubList.push({
							"키": ret["msp"]["contents"]["items"][i]["roundInfo"]["clubSeq"]
							, "라운드키": ret["msp"]["contents"]["items"][i]["roundInfo"]["roundSeq"]
							, "동호회명": ret["msp"]["contents"]["items"][i]["clubName"]
							, "라운드정보": { 
								"일자":ret["msp"]["contents"]["items"][i]["roundInfo"]["reservDate"]
								, "요일": ret["msp"]["contents"]["items"][i]["roundInfo"]["reservDay"]
								,"코스명":ret["msp"]["contents"]["items"][i]["roundInfo"]["golfclubCourseInfo"]
								,"진행상태":ret["msp"]["contents"]["items"][i]["roundInfo"]["procStatus"]
							}
							, "제목": ret["msp"]["contents"]["items"][i]["roundInfo"]["title"]
							, "회원유무": ret["msp"]["contents"]["items"][i]["clubMember"]["memberStatus"]
							
						});
					}
				}
				
				$(thisClass).trigger("evtFinishScheduleClubList");
			});
			// ajax 끝			
		}
		, getScheduleClubData: function(){
			return this.scheduleClubList;
		}
		, getScheduleClubPageData: function(){
			return this.scheduleClubPageData;
		}
		, setScheduleClubRequest: function(key, val){
			this.scheduleClubRequest[key] = val;
		}
		, getScheduleClubRequest: function(key){
			return this.scheduleClubRequest[key];
		}		
//------------------------ 인기동호회-----------------------------//		
		, getPopularClubList: function(){
			var thisClass = this;
			
			// ajax 시작			
			//parameter setting and run
			_gf.ajax({
				"sid":"CL001",
				"servicename":"getList",
				"listcount":5,
				"currpageno":1
			}, {
				"scope": 2
				, "categoryId": ""
			}, function(ret){
				
				// callback and mapping
				thisClass.popularClubList = [];				
				
				if(ret["msp"]["contents"]["items"]){
					if(!ret["msp"]["contents"]["items"].length){
						ret["msp"]["contents"]["items"] = new Array(ret["msp"]["contents"]["items"]);
					}
					for(var i=0;i<ret["msp"]["contents"]["items"].length;i++){
						thisClass.popularClubList.push({
							"키": ret["msp"]["contents"]["items"][i]["clubSeq"]
							, "이미지":  ret["msp"]["contents"]["items"][i]["bannerUrl"]
							, "동호회명": ret["msp"]["contents"]["items"][i]["clubName"]
							, "아이디": ret["msp"]["contents"]["items"][i]["userMaster"]["userId"]
							, "닉네임": ret["msp"]["contents"]["items"][i]["userMaster"]["nickname"]
							, "회원수": ret["msp"]["contents"]["items"][i]["memberCnt"]
							, "댓글수": ret["msp"]["contents"]["items"][i]["newBoardCnt"]
							, "동호회설명": ret["msp"]["contents"]["items"][i]["clubDesc"]
							, "프로필": []
						});
					}
					
				}
				
				$(thisClass).trigger("evtFinishPopularClubList");
			}); 
			// ajax 끝
		}
		, getPopularClubData: function(){
			return this.popularClubList;
		}
		, setPopularClubRequest: function(key, val){
			this.popularClubRequest[key] = val;
		}
		, getPopularClubRequest: function(key){
			return this.popularClubRequest[key];
		}		
//------------------------ 인기동호회-----------------------------//
		
	}
	
	
	// 컨트롤
	function clsControl()
	{
		this.objComm = null;
		
		this.objClubCategory = null;
		this.objSearchType = null;
		this.objSearchText = null;		
		
		this.objClubListCategory = null;
		this.objClubListCategoryPage = null;
		
		this.objClubListNew = null;
		this.objClubListNewPage = null;
		
		this.objClubListPopular = null;
		this.objClubListPopularPage = null;
		
		this._init();
	}
	
	clsControl.prototype = {
		_init: function(){
			this.objComm = new clsComm();
			
			this.objClubCategory = new clsClubCategory();
			this.objSearchType = new clsSearchType();
			this.objSearchText = new clsSearchText();
			this.objSearchCategory = new clsSearchCategory();
		
			this.objClubListCategory = new clsClubListCategory();
			this.objClubListCategoryPage = new _gf.makePaging($("#idCategoryClubListPage"), 10, 10);
			
			this.objClubListNew = new clsClubListNew();
			this.objClubListNewPage = new _gf.makeTinyPaging($("#idNewClubListPage"), 5);
			
			this.objClubListPopular = new clsClubListPopular();
			
			this.objClubListSchedule = new clsClubListSchedule();
			this.objClubListSchedulePage = new _gf.makeTinyPaging($("#idScheduleClubListPage"), 5);
			
			this._bind();
			
			//카테고리구분 조회
			this.objComm.getCategory();
						
			//동호회카테고리 조회-->카테고리항목 조회완료후 조회하도록 수정
			this.objClubListCategory.spinStart();			
						
			//신규동호회 조회
			this.objClubListNew.spinStart();		
			this.objComm.setNewClubRequest("페이지",1);
			this.objClubListNewPage.setPage(1);
			this.objComm.getNewClubList();
			//라운드 조회
			this.objClubListSchedule.spinStart();		
			this.objComm.setScheduleClubRequest("페이지",1);
			this.objClubListSchedulePage.setPage(1);
			this.objComm.getScheduleClubList();
			//인기동호회 조회
			this.objClubListPopular.spinStart();					
			this.objComm.getPopularClubList();
		}
		, _bind: function(){
			var thisClass = this;
			
			// 카테고리구분 조회 완료이벤트
			$(this.objComm).bind("evtFinishCategory", function(){
				var thisData = this.getCategoryData();
								
				thisClass.objSearchCategory.setList(thisData);
				thisClass.objClubCategory.setList(thisData);	
				
				// 카테고리 전체로 default 설정
				thisClass.objClubCategory.setIdx(0);
				
				//동호회카테고리 조회
				//thisClass.objClubListCategory.spinStart();			
				thisClass.objComm.setCategoryClubRequest("카테고리키","");
				thisClass.objComm.setCategoryClubRequest("검색어","");
				thisClass.objComm.setCategoryClubRequest("페이지",1);			
				thisClass.objClubListCategoryPage.setPage(1);
				thisClass.objComm.getCategoryClubList();
			});
			
			// 카테고리목록 조회 완료이벤트
			$(this.objComm).bind("evtFinishCategoryClubList", function(){
				var thisData = this.getCategoryClubData();
				var pageData = thisClass.objComm.getCategoryClubPageData();
				
				thisClass.objClubListCategory.spinEnd();				
				thisClass.objClubListCategory.setList(thisData);
				thisClass.objClubListCategoryPage.setTotalCount(pageData["전체수"]);
				thisClass.objClubListCategoryPage.display();
			});
			// 카테고리목록 페이지이동 이벤트
			$(this.objClubListCategoryPage).bind("evtPageClick", function(){
				var thisPage = this.getPage();
				
				thisClass.objComm.setCategoryClubRequest("페이지", thisPage);
				thisClass.objClubListCategory.spinStart();
				thisClass.objComm.getCategoryClubList();
			});
			// 신규동호회 조회 완료이벤트
			$(this.objComm).bind("evtFinishNewClubList", function(){
				var thisData = this.getNewClubData();
				var pageData = thisClass.objComm.getNewClubPageData();
				
				thisClass.objClubListNew.spinEnd();
				thisClass.objClubListNew.setList(thisData);
				thisClass.objClubListNewPage.setTotalCount(pageData["전체수"]);
				thisClass.objClubListNewPage.display();
				
				//프로필조회
				for(var i=0;i<thisData.length;++i){									
					_gf.getMemberInfo({
						"아이디": thisData[i]["아이디"]
						, "인덱스": i
						, "콜백": function(res, info, arg){
							thisClass.objClubListNew.addProfile(arg["인덱스"], info);
						}
					});
				}
			});			
			// 신규동호회 페이지이동 이벤트
			$(this.objClubListNewPage).bind("evtPageClick", function(){
				var thisPage = this.getPage();
				
				thisClass.objComm.setNewClubRequest("페이지", thisPage);
				thisClass.objClubListNew.spinStart();
				thisClass.objComm.getNewClubList();
			});
			// 동호회라운드 조회 완료이벤트
			$(this.objComm).bind("evtFinishScheduleClubList", function(){
				var thisData = this.getScheduleClubData();
				var pageData = thisClass.objComm.getScheduleClubPageData();
				
				thisClass.objClubListSchedule.spinEnd();
				thisClass.objClubListSchedule.setList(thisData);
				thisClass.objClubListSchedulePage.setTotalCount(pageData["전체수"]);
				thisClass.objClubListSchedulePage.display();
			});			
			// 동호회라운드 페이지이동 이벤트
			$(this.objClubListSchedulePage).bind("evtPageClick", function(){
				var thisPage = this.getPage();
				
				thisClass.objComm.setScheduleClubRequest("페이지", thisPage);
				thisClass.objClubListSchedule.spinStart();
				thisClass.objComm.getScheduleClubList();
			});
			// 인기동호회 조회 완료이벤트
			$(this.objComm).bind("evtFinishPopularClubList", function(){
				var thisData = this.getPopularClubData();
				
				thisClass.objClubListPopular.spinEnd();
				thisClass.objClubListPopular.setList(thisData);
				
				//프로필조회
				for(var i=0;i<thisData.length;++i){									
					_gf.getMemberInfo({
						"아이디": thisData[i]["아이디"]
						, "인덱스": i
						, "콜백": function(res, info, arg){
							thisClass.objClubListPopular.addProfile(arg["인덱스"], info);
						}
					});
				}
			});	
				
			// 카테고리 탭클릭 이벤트
			$(this.objClubCategory).bind("evtTabClick", function(event, idx){
				event.preventDefault();
								
				if(thisClass.objClubCategory.getIdx() == idx) return;
				
				thisClass.objClubCategory.setIdx(idx);
				
				thisClass.objComm.setCategoryClubRequest("카테고리키", (idx==0?"":idx));
				thisClass.objComm.setCategoryClubRequest("페이지", 1);
				thisClass.objClubListCategoryPage.setPage(1);
				
				thisClass.objClubListCategory.spinStart();
				thisClass.objComm.getCategoryClubList();
			});
			
			//전체동호회 버튼 이벤트
			$("div#container section#main_content div.club_home article.depth2_tab ul img[alt=전체동호회]").click(function(event){
				event.preventDefault();					
				document.location.href = "../club/club.html";
			});
			
			//나의동호회 버튼 이벤트
			$("div#container section#main_content div.club_home article.depth2_tab ul img[alt=나의동호회]").click(function(event){
				event.preventDefault();					
				document.location.href = "../club/club_join.html";
			});
			
			//동호회개설 버튼 이벤트
			$(".btn_depth a img").click(function(event){
					event.preventDefault();					
					document.location.href = "../club/club_creat.html";
			});
			
			// 검색 이벤트
			$("article.golf_board_search :image").click(function(event){
				event.preventDefault();
				
				var types= thisClass.objSearchType.getValue();
				var texts = thisClass.objSearchText.getValue();
				var category = thisClass.objSearchCategory.getValue();
				
				if(!thisClass.objSearchText.isValid() & thisClass.objSearchType.getValue() != 0){
					alert(thisClass.objSearchText.getError());
					thisClass.objSearchText.focus();
					return;
				}
				
				event.preventDefault();					
				document.location.href = "../club/club_list.html?q_type="+ types +"&q_text="+ texts + "&q_cate=" + category;
				
			});
			
		}
	}
	
	document.objControl = new clsControl();
});